import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Antd from 'ant-design-vue'
import axios from 'axios'
import tool from '../public/js/tool'
import login from './views/login.vue'
import {isReturnTrue} from "@/util/util";
import  _enum from './enum/enum'
// import './assets/js/enum'


const app=createApp(App)
app.use(Antd).use(store).use(router).use(tool).use(_enum).mount('#app')
app.config.globalProperties.$isReturnTrue=isReturnTrue

axios.interceptors.request.use(function(config){
    let userInfo=null;
    try {
        userInfo=store.state.userInfo==null||store.state.userInfo===''?null:JSON.parse(store.state.userInfo)
    }
    catch (e){
        console.log("用户未登录")
    }
        if(userInfo!=null){
            const _token=JSON.parse(window.localStorage.getItem("USERINFO")).token;
            console.log("用户信息"+JSON.parse(window.localStorage.getItem("USERINFO")).phone)
            config.headers.Authorization=_token
        }
        else{
            console.log("用户未登录");
        }
        return config;
    }
);

axios.interceptors.response.use(function (response){
        console.log('返回结果：',response);
        return response;
    },error=>{
        console.log('返回错误',error);
        if(error.response.status!=undefined&&error.response.status==401){
            //用UserInfo里的phone调用refreshToken接口，重新获取token
            store.commit("setUserInfo",null)
            router.push("/login").then(r => alert("请登录"))
        }
        return Promise.reject(error)
    }
)
axios.defaults.baseURL="http://localhost:8000"
console.log(process.env.NODE_DEV)
console.log(process.env.VUE_APP_SERVER)




